#pragma once

#include <iostream>
#include <string>
#include <cstdio>
#include <cstdarg>
#include <ctime>

const int MAX_LEN = 1024;

enum LOG_ENUM
{
    INFO = 1,
    WARNING,
    ERROR,
    FATAL
};

#define Log(Level, format, ...) log(#Level, __LINE__, __FILE__, format, ##__VA_ARGS__)

void log(const char* Level, int line, const char* file, const char* format, ...)
{
    char buffer[MAX_LEN] = { 0 };
    va_list ap;
    va_start(ap, format);
    vsnprintf(buffer, MAX_LEN - 1, format, ap);
    va_end(ap);
    time_t nowtime;
    time(&nowtime);
    tm* p = localtime(&nowtime);
    printf("%04d-%02d-%02d %02d:%02d:%02d "        \
    , p->tm_year + 1900, p->tm_mon + 1, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec);
    printf("| %-7s | %s   [%s]<%d>\n", Level, buffer, file, line);
}
